import 'package:flutter/material.dart';

import 'input_field.dart';

class AppSearchBar extends StatelessWidget {
  /// 是否点击触发重定位
  final Function? redirect;
  final bool searchIconVisible;
  final Widget? prefix;

  const AppSearchBar({super.key, this.redirect, this.searchIconVisible = true, this.prefix});

  @override
  Widget build(BuildContext context) {

    /// when searchIconVisible is true, default icon
    Widget iconPrefix = prefix ?? const Icon(
      Icons.search_rounded,
      size: 25,
      color: Colors.grey,
    );

    return Stack(
      children: [
        InputField(
          backgroundColor: Colors.white,
          borderRadius: 90,
          hintText: 'Search',
          minHeight: 30,
          padding: EdgeInsets.symmetric(horizontal: 15, vertical: 5),
          prefix: searchIconVisible ? iconPrefix : null,
        ),
        redirect != null
            ? Positioned.fill(
          child: GestureDetector(
            onTap: () {
              redirect?.call();
            },
          ),
        )
            : const SizedBox(),
      ],
    );
  }
}
